<?php

namespace app\admin\controller\home;

use app\common\controller\Backend;
use think\Db;

/**
 * 诊疗项目表
 *
 * @icon fa fa-circle-o
 */
class Diagnosis extends Backend
{

    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];
    protected $relationSearch = true;

    /**
     * @var \app\admin\model\User
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Diagnosis;

        $categorys = Db::table('fa_categorys')
            ->where('type',2)
            ->select();
        $this->view->assign('categorys', $categorys);
    }

    /**
     * 查看
     */
    public function index()
    {

        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {

            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model
                //->with(['categorys'=>['id,name']])
                ->with([
                    'categorys' => function ($query) {
                        $query->withField('id,name');
                    }
                ])
                ->where($where)
                //->where('admin_id', 'in', [0])
                ->order('id', $order)
                ->paginate($limit);

            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }

        return $this->view->fetch();
    }


}
